#include "mywidget.h"
#include "ui_mywidget.h"
#include <QFileInfo>
#include <QFileDialog>

#include <QDateTime>
#include <QDebug>

MyWidget::MyWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::MyWidget)
{
    ui->setupUi(this);

    connect(ui->chose_file_btn, &QPushButton::clicked, [=]() {
        QString path = QFileDialog::getOpenFileName(this, "打开文件", "C:\\Users\\Kern\\Desktop\\");
        //ui->->setText(path);
        ui->file_path->setText(path);

        QFile file(path);
        file.open(QFile::ReadOnly);

        QByteArray array = file.readAll();
//        ui->textEdit->setText(array);
        ui->content->setText(array);


        QFileInfo info(path);

        // 文件大小
        qint64 size = info.size();  // 单位是 字节
        this->ui->size->setText(tr("%1").arg(size));

        // 文件后缀
        QString suffix = info.suffix();
        this->ui->suffix->setText(suffix);
        // 文件创建日期
        const QString format = "yyyy-MM-dd";
        QString createTimeStr = info.birthTime().toString(format);
        this->ui->create_date->setText(createTimeStr);
        // 最后修改日期
        QString lmTimeStr = info.lastModified().toString(format);
        this->ui->modify_date->setText(lmTimeStr);



    });

}

MyWidget::~MyWidget()
{
    delete ui;
}

